package com.springbootee;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableWebMvc
@EnableKnife4j
public class SwaggerConfiguration implements WebMvcConfigurer {

    /**
     * @deprecated :定制我的API文档
     * @author: dell
     * @time: 2021/10/13 11:06
     */
    @Bean
    public Docket userManage(){
        //需要用到ApiInfoBuilder来定制我的API文档
        ApiInfo apiInfo=new ApiInfoBuilder()
                //API文档的标题
                .title("生成了一个自己的API文档")
                //API文档的描述
                .description("描述API文档")
                .termsOfServiceUrl("")
                .version("版本号：0.1")
                .build();
        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.springbootee"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * @deprecated: 如果近期继承过 原来继承WebMvcConfigurationSupport  改为 WebMvcConfigurer
     * @parms :
     * @return:
     * @author: dell
     * @time: 2021/10/13 16:52
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

    }


    /**
     * @deprecated: 定制中隐藏UI的Models模块
     * @author: dell
     * @time: 2021/10/13 11:20
     */
    @Bean
    public UiConfiguration uiConfig(){
    return UiConfigurationBuilder.builder()
            .deepLinking(true)
            .displayOperationId(false)
            .defaultModelsExpandDepth(-1)
            .defaultModelExpandDepth(0)
            .displayRequestDuration(false)
            .docExpansion(DocExpansion.NONE)
            .filter(false)
            .maxDisplayedTags(null)
            .operationsSorter(OperationsSorter.ALPHA)
            .showExtensions(false)
            .tagsSorter(TagsSorter.ALPHA)
            .validatorUrl(null)
            .build();

    }
}
